home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / snmp_0_1.zip / snmp-0.1 / aka / snmp / MibManagerMosy.java < prev    next >
Text File  |  1997-06-09  |  4KB  |  167 lines

  1. /*
  2. Snmp Library
  3. Copyright (C) 1997 Alex Kowalenko Associates Pty Ltd. All rights reserved.
  4.  
  5. $Id: MibManagerMosy.java,v 1.1 1997/05/21 13:25:18 alex Exp $
  6.  
  7. This software maybe be free distributed, any any form, without fee, 
  8. but may not be modified in any way without express permission of 
  9. the directors of Alex Kowalenko Associates Pty Ltd. 
  10.  
  11. Alex Kowalenko Associates Pty Ltd makes no representations or
  12. warranties about the suitabililty of the software, not even the
  13. implied warranty of merchantability or fitness for any particular
  14. purpose.    
  15. */
  16.  
  17. package aka.snmp;
  18.  
  19. import java.util.*;
  20. import java.io.*;
  21.  
  22. /**
  23.  * This class extends MibManager with a routine to read MOSY compiled files.
  24.  * The mosy compiler is part of the ISODE package 6.0, and is obsolete.
  25.  * @see MibManager
  26.  * @version     $Id: MibManagerMosy.java,v 1.1 1997/05/21 13:25:18 alex Exp $
  27.  * @author      Alex Kowalenko
  28.  */
  29.  
  30. public class MibManagerMosy extends MibManager {
  31.  
  32. /**
  33.  * Constructor
  34.  */
  35.  
  36.   public MibManagerMosy() {
  37.       super();
  38.   };
  39.   
  40. /**
  41.  * Reads from SNMP Objects from MOSY processed file and stores them.
  42.  * @deprecated - MOSY compiler for SNMP V1 not avaliable
  43.  * 
  44.  */
  45.  
  46.   public void addFromMosyFile(String fileName) 
  47.       throws FileNotFoundException, SnmpMibException {
  48.       
  49.       BufferedReader input = new BufferedReader(new FileReader(fileName));
  50.       
  51.       try {
  52.           // input.skipBytes(0); // needed  to init DataInputStream 
  53.           while(true) { 
  54.                   // Exception on readline() exits loop
  55.           String line = input.readLine();
  56.           if(line == null)
  57.               return;
  58.  
  59.           line = line.trim();
  60.    
  61.           StringTokenizer tokens = new StringTokenizer(line, " \t");
  62.           String firstToken;
  63.  
  64.           if(tokens.countTokens() == 0)
  65.               continue;
  66.           firstToken = tokens.nextToken();
  67.  
  68.           if(firstToken.equals("--"))  // comment
  69.               continue;
  70.     
  71.           if(tokens.countTokens() == 1 ) {
  72.               
  73.               String name = firstToken;
  74.               String id = tokens.nextToken();
  75.               // top tree definitions
  76.               ObjectId baseID = baseForm(id);
  77.               if(!baseID.isValid())
  78.               throw new SnmpMibException("Can't find SNMP object : " + id);
  79.       
  80.               SnmpObject obj = new SnmpObject(name, baseID.toString());
  81.               if(_tableName.contains(name)) 
  82.               throw new SnmpMibException("Duplicate object : " + 
  83.                              id);
  84.               _tableName.put(name, obj);
  85.               _tableID.put(baseID, obj);  
  86.           }
  87.           else if(tokens.countTokens() == 4) {
  88.               String name = firstToken;
  89.               String id = tokens.nextToken();
  90.               String typeStr = tokens.nextToken();
  91.               String accessStr = tokens.nextToken();
  92.               String statusStr = tokens.nextToken();
  93.  
  94.               ObjectId baseID = baseForm(id);
  95.               Access acc;
  96.               Status stat;
  97.               String type;
  98.       
  99.               if(!baseID.isValid())
  100.               throw new SnmpMibException("Can't find SNMP object : " + id);
  101.             
  102.               if(typeStr.equals("Aggregate")) {
  103.               // Aggregates are node objects in the tree
  104.               SnmpObject obj = new SnmpObject(name, 
  105.                               baseID.toString());
  106.               if(_tableName.contains(name)) 
  107.                   throw new SnmpMibException("Duplicate object : " + id);
  108.               _tableName.put(name, obj);
  109.               _tableID.put(baseID, obj); 
  110.               }
  111.               else {
  112.               acc = new Access(accessStr);
  113.               stat = new Status(statusStr);
  114.         
  115.               if(typeStr.equals("DisplayString") 
  116.                  || typeStr.equals("OctetString")
  117.                  || typeStr.equals("Opaque"))
  118.                   type = "STRING";
  119.               else if(typeStr.equals("NetworkAddress"))
  120.                   type = "IpAddress";
  121.               else
  122.                   type = typeStr;
  123.         
  124.               SnmpObject obj = new SnmpObject(name, 
  125.                               baseID, 
  126.                               type, 
  127.                               acc, 
  128.                               stat);
  129.               if(_tableName.contains(name))
  130.                   throw new SnmpMibException("Duplicate object : " + id);
  131.               _tableName.put(name, obj);
  132.               _tableID.put(baseID, obj);
  133.               }
  134.           }
  135.           }
  136.       } catch(IOException e) {
  137.           return;
  138.       };
  139.   };
  140.  
  141. /**
  142.  * Test Harness
  143.  */
  144.  
  145.   public static void main(String args[]) {
  146.       PrintStream out = System.out;
  147.  
  148.       out.println("Creating SNMP MIB MANAGER");
  149.       MibManagerMosy mibs = new MibManagerMosy();
  150.  
  151.       out.println("Reading SNMP mib");
  152.       try {
  153.       mibs.addFromMosyFile("x.mibs");
  154.       } catch(FileNotFoundException e) {
  155.       out.println("File not found");
  156.       return;
  157.       } catch(Exception e) {
  158.       out.println("Exception");
  159.       e.printStackTrace();
  160.       mibs.dump();
  161.       };
  162.  
  163.       mibs.dump();
  164.   }
  165.  
  166. }
  167.